<?php

header("Content-Type: text/html;charset=utf8");

class VersionDb {

    private $mysql;

    public function __construct(InMysql $mysql = null) {
        if ($mysql == null) {
            $this->mysql = new InMysql();
        } else {
            $this->mysql = $mysql;
        }
    }

    public function listVersion() {
        $sql = "select * from ver";
        return $this->mysql->fetchData($sql);
    }

    public function addVersion($name, $ver, $addr, $scene) {
        $sql = "insert into ver(name,ver,addr,scene,ctime) values('" . $name . "','" . $ver . "','" . $addr . "','" . $scene . "',UNIX_TIMESTAMP())";
        return $this->mysql->insertData($sql);
    }

    public function getVersionByName($name) {
        $sql = "select * from ver where name = '" . $name . "'";
        return $this->mysql->fetchData($sql);
    }

    public function editVersion($id, $name, $ver) {
        $sql = "update ver set name = '" . $name . "',ver = '" . $ver . "' where id = " . $id;
        return $this->mysql->executeData($sql);
    }

    public function deleteVersion($id){
        $sql = "delete from ver where id = " . $id;
        return $this->mysql->executeData($sql);
    }
}

?>